export const getLocation = () => {
    return new Promise((resolve, reject) => {
        uni.chooseLocation({
            success: (res) => {
                resolve(res); // 成功返回地址信息
            },
            fail: () => {
                uni.getSetting({
                    success: (res) => {
                        const status = res.authSetting;
                        if (!status['scope.userLocation']) {
                            uni.showModal({
                                title: "是否授权获取当前位置",
                                content: "需要获取您的地理位置，请确认授权，否则地图功能将无法使用",
                                success: (tip) => {
                                    if (tip.confirm) {
                                        uni.openSetting({
                                            success: (data) => {
                                                if (data.authSetting['scope.userLocation'] === true) {
                                                    uni.showToast({ title: "授权成功", icon: "success", duration: 1000 });
                                                    uni.chooseLocation({
                                                        success: (res) => resolve(res),
                                                        fail: (err) => reject(err)
                                                    });
                                                } else {
                                                    uni.showToast({ title: "授权失败", icon: "none", duration: 1000 });
                                                    reject("授权失败");
                                                }
                                            },
                                            fail: (err) => reject(err)
                                        });
                                    } else {
                                        reject("用户拒绝授权");
                                    }
                                }
                            });
                        }
                    },
                    fail: (err) => {
                        uni.showToast({ title: "调用授权失败", icon: "none", duration: 1000 });
                        reject(err);
                    }
                });
            }
        });
    });
}
